<template>
	<view class="container">
		<template v-for="(item, index) in list">
			<view class="inform-box">
				<view class="inform-box-title">
					<h1>{{item.title}}</h1>
					<text>{{$util.dateUtils.format(item.createTime)}}</text>
				</view>

				<image v-if="item.previewImage != ''" class="maxImage" :src="item.previewImage" mode="aspectFill"></image>

				<view class="inform-box-body">
					<text>{{item.remark}}</text>
				</view>

				<view class="inform-box-bottom" @click="navTo(item)">
					<h1>点击查看</h1>
					<tui-icon name="arrowright" color="rgba(61, 61, 61, 0.3)" size="26"></tui-icon>
				</view>

			</view>

		</template>
		
		<!-- 没有商品 -->
		<view class="nodetails" style="height: 510px" v-if="list.length == 0">
		  <view class="nodetails_img">
		    <image src="http://qichong-1256206693-1256206693.cos.ap-nanjing.myqcloud.com/upload/20210617/3a7b53543eb8e61ccf6b16369db10a00.png" mode="widthFix" class="maxImage"></image>
		  </view>
		  <text>去发动态...</text>
		</view>
	</view>
</template>

<script>
	import {
		notice
	} from '@/api/message.js'
	export default {
		data() {
			return {
				title: '',
				type: 0, //0系统通知 1 活动通知 2 门店通知
				list: []
			};
		},
		onLoad(option) {
			this.title = option.title;
			this.type = option.type;

			uni.setNavigationBarTitle({
				title: option.title + '通知'
			})
			this.notice();
		},
		methods: {
			navTo(data) {
				let url = "";
				if(data.link && data.link.length > 0){
					url = data.link;
				}else if(data.content && data.content.length > 0){
					url = '/subpkg/message/noticedetail?title='+ encodeURIComponent(data.title) + '&time='+ data.createTime + '&content=' + encodeURIComponent(data.content);
				}else if(data.type === 2 || data.type === 7){//活动发布或奖励
					url = '/subpkg/activity_particulars/activity_particulars?id=' + data.associatedId;
				}
				
				uni.navigateTo({
					url: url
				})
			},
			notice() {
				let that = this;
				notice(that.type).then(res => {
					that.list = res.data;
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F5F5F5;
	}

	.container {
		padding: 30rpx 24rpx 0;

		.inform-box {
			box-sizing: border-box;
			// height: 400rpx;
			background-color: #fff;
			border-radius: 20rpx;
			padding: 36rpx 48rpx;
			margin-bottom: 30rpx;

			.inform-box-title {
				display: flex;
				justify-content: space-between;
				align-items: center;

				h1 {
					font-size: 34rpx;
					color: rgba(61, 61, 61, 1);
					font-weight: 500;
				}

				text {
					font-size: 26rpx;
					color: rgba(61, 61, 61, 0.6);
				}
			}


			.inform-box-body {
				margin: 35rpx 0 50rpx;

				text {
					font-size: 28rpx;
					color: rgba(61, 61, 61, 0.8);
					line-height: 50rpx;
				}
			}

			.inform-box-bottom {
				padding-top: 30rpx;
				border-top: 1rpx solid #f1f1f1;
				display: flex;
				justify-content: space-between;
				align-items: center;

				h1 {
					font-size: 28rpx;
				}
			}

			.maxImage {
				width: 100%;
				height: 322rpx;
				border-radius: 20rpx;
				margin-top: 35rpx;
			}
		}
	}
	
	.nodetails {
		display: flex;
		align-items: center;
		justify-content: center;
		flex-direction: column;
		padding-bottom: 128rpx;
	
		.nodetails_img {
			.maxImage {
				width: 184rpx;
				height: 322rpx;
			}
		}
	
		text {
			font-size: 30rpx;
			margin-top: 20rpx;
			color: rgba(61, 61, 61, 0.3);
		}
	}
</style>
